﻿using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using WebApplication3.Data;
using WebApplication3.Model;

namespace WebApplication3.Data
{
    [Route("api/[controller]")]
    [ApiController]
    public class QuestionController : ControllerBase
    {
        private readonly ApplicationDbContext _context;

        public QuestionController(ApplicationDbContext context)
        {
            _context = context;
        }
        // GET: api/question/options/{categoryId}/{questionId}
        [HttpGet("options/{categoryId}/{questionId}")]
        public ActionResult<string[]> GetQuestionOptions(int categoryId, int questionId)
        {
            var question = _context.Questions
                .FirstOrDefault(q => q.Id == questionId && q.CategoryId == categoryId);

            if (question == null)
            {
                return NotFound();
            }

            // Assuming A, B, C, D are the options properties in your model
            string[] options = { question.A, question.B, question.C, question.D };

            return options;
        }
    }
}
